package com.wongoing.api.wechat.pub.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能说明：发送消息实体类 修改说明：
 * 
 * @author zhenglibing
 * @date 2018年1月8日 下午5:24:19
 * @version 0.1
 */
public class SendMsg implements Serializable {

	private String touser;			//成员ID列表（消息接收者，多个接收者用‘|’分隔，最多支持1000个）。特殊情况：指定为@all，则向关注该企业应用的全部成员发送
	private MsgType msgtype;		//消息类型
	private TextMsg text;			//文本消息
	private MediaMsg image;			//图片消息
	private MediaMsg voice;			//音频消息
	private MediaMsg video;			//视频消息
	private MediaMsg music;			//音乐文件消息
	private List<NewsMsg> news = new ArrayList<NewsMsg>();		//图文消息
	private MediaMsg mpnews;		//微信后台的内部图文消息
	private WxCardMsg wxcard;		//卡券消息

	public String getTouser() {
		return touser;
	}

	public void setTouser(String touser) {
		this.touser = touser;
	}

	public MsgType getMsgtype() {
		return msgtype;
	}

	public void setMsgtype(MsgType msgtype) {
		this.msgtype = msgtype;
	}

	public TextMsg getText() {
		return text;
	}

	public void setText(TextMsg text) {
		this.text = text;
	}

	public MediaMsg getImage() {
		return image;
	}

	public void setImage(MediaMsg image) {
		this.image = image;
	}

	public MediaMsg getVoice() {
		return voice;
	}

	public void setVoice(MediaMsg voice) {
		this.voice = voice;
	}

	public MediaMsg getVideo() {
		return video;
	}

	public void setVideo(MediaMsg video) {
		this.video = video;
	}

	public MediaMsg getMusic() {
		return music;
	}

	public void setMusic(MediaMsg music) {
		this.music = music;
	}

	public List<NewsMsg> getNews() {
		return news;
	}

	public void setNews(List<NewsMsg> news) {
		this.news = news;
	}

	public MediaMsg getMpnews() {
		return mpnews;
	}

	public void setMpnews(MediaMsg mpnews) {
		this.mpnews = mpnews;
	}

	public WxCardMsg getWxcard() {
		return wxcard;
	}

	public void setWxcard(WxCardMsg wxcard) {
		this.wxcard = wxcard;
	}

	/**
	 * 功能说明：获取对象的JSON格式字符串
	 * 修改说明：
	 * @author zhenglibing
	 * @date 2018年1月8日 下午5:34:12
	 * @return 返回对象的JSON字符串
	 */
	public String toJsonString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append("{");
        sb.append("\"touser\":").append("\"").append(this.touser).append("\"").append(",");
        sb.append("\"msgtype\":").append("\"").append(this.msgtype.toString().toLowerCase()).append("\"").append(",");
        if (this.msgtype == MsgType.Text)
        {
            sb.append("\"text\":").append(this.text.toJsonString());
        }
        else if (this.msgtype == MsgType.Image)
        {
            sb.append("\"image\":").append(this.image.toJsonString());
        }
        else if (this.msgtype == MsgType.Voice)
        {
            sb.append("\"voice\":").append(this.voice.toJsonString());
        }
        else if (this.msgtype == MsgType.Video)
        {
            sb.append("\"video\":").append(this.video.toVideoJsonString());
        }
        else if (this.msgtype == MsgType.Music)
        {
            sb.append("\"music\":").append(this.music.toMusicJsonString());
        }
        else if (this.msgtype == MsgType.News)
        {
            sb.append("\"news\":{\"articles\":[");
            if (null != this.news && this.news.size() > 0)
            {
                for (int i = 0; i < this.news.size(); i++)
                {
                    if (i > 0)
                    {
                        sb.append(",");
                    }
                    sb.append(this.news.get(i).toJsonString());
                }
            }
            sb.append("]}");
        }
        else if (this.msgtype == MsgType.Mpnews)
        {
            sb.append("\"mpnews\":").append(this.mpnews.toJsonString());
        }
        else if (this.msgtype == MsgType.Wxcard)
        {
            sb.append("\"wxcard\":").append(this.wxcard.toJsonString());
        }
        else
        {
            //默认为文本消息
            sb.append("\"text\":").append(this.text.toJsonString()).append(",");
        }
        sb.append("}");
        return sb.toString();
    }
}
